from django import newforms as forms
from forum.models import Forum,Post,Topic


class TopicForm(forms.Form):
    title = forms.CharField(label="Naslov",max_length=64)
    forum_id = forms.ChoiceField(label="Forum",choices = [(x.id,x.name) for x in Forum.active.all()])
    content = forms.CharField(label="Vsebina",widget=forms.widgets.Textarea)
    
    
    def save(self,user):
        topic = Topic()
        data = self.clean_data
        topic.content = data['content']
        topic.title = data['title']
        topic.forum_id = data['forum_id']
        topic.author_id = user.id
        topic.state = 'published'
        topic.save()
        return topic

    
